<?php if (!defined('BASEPATH')) {
	exit('No direct script access allowed');
}
/**
 * Class account extends MY_Controller
 * @author zhangchangshun
 * 移动端用户接口类(需求及需求发布)
 */
class needs extends API_Controller {

	public function __construct() {
		parent::__construct();
        if(ENVIRONMENT=='production'){
            $this->_auto();
        }
        $this->load->model('upload_model','mupload');
        $this->load->model('category_model','mcategory');
        $this->load->model('needs_model','mneeds');
        $this->load->model('upload_model','mupload');
        $this->load->model('claim_model','mclaim');
        $this->load->model('pay_logs_model', 'mpay_log');
        $this->load->model('account_model','maccount');
        $this->load->model('countdown_model','mcount_down');
        $this->load->model('balance_detail_model','mbalance');
        $this->load->model('need_order_model','mneedorder');
        $this->load->model('need_apply_model','mneedapply');
	}

    /**
     * 获取需求类型
     */
    public function get_category(){
        $info = $this->db->query("select id,title from boc_category where ctype in (30,31,32)")->result_array();
        if(empty($info)){
            $this->vdata['returnCode']   = '250';
            $this->vdata['returnInfo'] = '请求失败';
            $this->vdata['secure']     = JSON_SECURE;
            $this->vdata['content']= array();
        }else{
            $this->vdata['returnCode']   = '200';
            $this->vdata['returnInfo'] = '操作成功';
            $this->vdata['secure']     = JSON_SECURE;
            $this->vdata['content']= $info;
        }
        $this->_send_json($this->vdata);
    }

    /**
     * 根据选择的类型来判断属于哪个大类
     */
    public function get_parent(){
        $data = $this->input->post();
        $id = $data['id'];
        if(isset($id)){
            $cate_info = $this->mcategory->get_one(array('id'=>$id),'id,title,ctype');
            $info = array();
            if(empty($cate_info)){
                $this->vdata['returnCode']   = '250';
                $this->vdata['returnInfo'] = '请求失败';
                $this->vdata['secure']     = JSON_SECURE;
                $this->vdata['content']= array();
            }else{
                if($cate_info['ctype']==30){
                    $info['id'] = $cate_info['id'];
                    $info['title'] = $cate_info['title'];
                    $info['parent'] = '悬赏任务';
                    $info['pid'] = $cate_info['ctype'];

                }elseif($cate_info['ctype']==31){
                    $info['id'] = $cate_info['id'];
                    $info['title'] = $cate_info['title'];
                    $info['parent'] = '活动';
                    $info['pid'] = $cate_info['ctype'];
                }elseif($cate_info['ctype']==32){
                    $info['id'] = $cate_info['id'];
                    $info['title'] = $cate_info['title'];
                    $info['parent'] = '需求对接';
                    $info['pid'] = $cate_info['ctype'];
                }
                $this->vdata['returnCode']   = '200';
                $this->vdata['returnInfo'] = '操作成功';
                $this->vdata['secure']     = JSON_SECURE;
                $this->vdata['content']= $info;
            }
        }else{
            $this->vdata['returnCode']   = '250';
            $this->vdata['returnInfo'] = '缺少参数';
            $this->vdata['secure']     = JSON_SECURE;
            $this->vdata['content']= array();
        }

        $this->_send_json($this->vdata);
    }

    /**
     * 发布创建需求（悬赏任务、活动、需求对接）
     */
    public function create_needs(){
        $user_info = $this->userinfo;
        if(!isset($user_info) && empty($user_info)){
            $this->vdata['returnCode']   = '250';
            $this->vdata['returnInfo'] = '请求失败';
            $this->vdata['secure']     = JSON_SECURE;
            $this->vdata['content']= array();
        }else{
            $user_id = $user_info['id'];
            //优先判断是否有发布的权限
            $last_cancel = $this->userinfo['last_cancel'];
            if($last_cancel==0 || $last_cancel+24*3600 < time()){
                $data = $this->input->post();
                if(!isset($data) && empty($data)){
                    $this->vdata['returnCode']   = '250';
                    $this->vdata['returnInfo'] = '缺少参数';
                    $this->vdata['secure']     = JSON_SECURE;
                    $this->vdata['content']= array();
                }else{
                    $type = $this->input->post('id');
                    $intro = $this->input->post('intro');
                    $pid = $this->input->post('pid');
                    if(!$type){
                        $this->vdata['returnCode']   = '250';
                        $this->vdata['returnInfo'] = '请选择需求类型';
                        $this->vdata['secure']     = JSON_SECURE;
                        $this->vdata['content']= array();
                    }elseif(!isset($intro) || $intro==''){
                        $this->vdata['returnCode']   = '250';
                        $this->vdata['returnInfo'] = '请填写需求描述';
                        $this->vdata['secure']     = JSON_SECURE;
                        $this->vdata['content']= array();
                    }elseif(!$pid){
                        $this->vdata['returnCode']   = '250';
                        $this->vdata['returnInfo'] = '请选择需求类型';
                        $this->vdata['secure']     = JSON_SECURE;
                        $this->vdata['content']= array();
                    }elseif($pid==30){
                        $needs_data['type'] = 1;
                        /**
                         * 悬赏任务情况（最小价格和最大价格判断）
                         */
                        $min_money = intval($this->input->post('min_money'));
                        $max_money = intval($this->input->post('max_money'));
                        if(!isset($min_money) || !$min_money){
                            $this->vdata['returnCode']   = '250';
                            $this->vdata['returnInfo'] = '请填写最小悬赏价格';
                            $this->vdata['secure']     = JSON_SECURE;
                            $this->vdata['content']= array();
                        }elseif(!isset($max_money) || !$max_money){
                            $this->vdata['returnCode']   = '250';
                            $this->vdata['returnInfo'] = '请填写最大悬赏价格';
                            $this->vdata['secure']     = JSON_SECURE;
                            $this->vdata['content']= array();
                        }elseif($min_money >= $max_money){
                            $this->vdata['returnCode']   = '250';
                            $this->vdata['returnInfo'] = '最小价格不能大于等于最大价格';
                            $this->vdata['secure']     = JSON_SECURE;
                            $this->vdata['content']= array();
                        }else{
                            $needs_data['min_money'] = $min_money;
                            $needs_data['max_money'] = $max_money;
                            $needs_data['margin'] = $max_money;   //支付的最大押金
                            $photos = $this->input->post('photos');
                            $needs_data['photos'] = isset($photos) ? $photos : '';
                            $needs_data['intro'] = strip_tags($intro);
                            $needs_data['uid'] = $user_id;
                            $needs_data['cate_id'] = $type;
                            $needs_data['order_sn'] = get_order_sn('boc_needs','S');
                            $needs_data['created'] = time();
                            $needs_data['expire_time'] = time()+24*3600;
                            $needs_data['countdown'] = time()+24*3600;
                            $needs_data['updated'] = time();
                            $needs_id = $this->mneeds->create($needs_data);
                            if($needs_id){
                                $this->vdata['returnCode']   = '200';
                                $this->vdata['returnInfo'] = '发布成功';
                                $this->vdata['secure']     = JSON_SECURE;
                                $this->vdata['content'] = array('need_id'=>$needs_id,'order_sn'=>$needs_data['order_sn'],'pid'=>$pid);
                            }else{
                                $this->vdata['returnCode']   = '200';
                                $this->vdata['returnInfo'] = '发布失败';
                                $this->vdata['secure']     = JSON_SECURE;
                                $this->vdata['content']= array();
                            }
                        }
                    }elseif($pid==31){
                        $needs_data['type'] = 2;
                        /**
                         * 活动情况（报名截止时间）
                         */
                        $end_time = $this->input->post('end_time');
                        if(!isset($end_time) || $end_time==''){
                            $this->vdata['returnCode']   = '250';
                            $this->vdata['returnInfo'] = '请填写报名截止时间';
                            $this->vdata['secure']     = JSON_SECURE;
                            $this->vdata['content']= array();
                        }elseif(intval($end_time) <= time()){
                            $this->vdata['returnCode']   = '250';
                            $this->vdata['returnInfo'] = '截止时间不能小于报名时间';
                            $this->vdata['secure']     = JSON_SECURE;
                            $this->vdata['content']= array();
                        }else{
                            $needs_data['end_time'] = $end_time;
                            $photos = $this->input->post('photos');
                            $needs_data['photos'] = isset($photos) ? $photos : '';
                            $needs_data['intro'] = strip_tags($intro);
                            $needs_data['uid'] = $user_id;
                            $needs_data['cate_id'] = $type;
                            $needs_data['status'] = 1;
                            $needs_data['claim_status'] = 1;
                            $needs_data['created'] = time();
                            $needs_data['updated'] = time();
                            $needs_id = $this->mneeds->create($needs_data);
                            if($needs_id){
                                $this->vdata['returnCode']   = '200';
                                $this->vdata['returnInfo'] = '发布成功';
                                $this->vdata['secure']     = JSON_SECURE;
                                $this->vdata['content'] = array('need_id'=>$needs_id,'pid'=>$pid);
                            }else{
                                $this->vdata['returnCode']   = '200';
                                $this->vdata['returnInfo'] = '发布失败';
                                $this->vdata['secure']     = JSON_SECURE;
                                $this->vdata['content']= array();
                            }
                        }
                    }else{
                        $needs_data['type'] = 3;
                        $photos = $this->input->post('photos');
                        $needs_data['photos'] = isset($photos) ? $photos : '';
                        $needs_data['intro'] = strip_tags($intro);
                        $needs_data['uid'] = $user_id;
                        $needs_data['cate_id'] = $type;
                        $needs_data['status'] = 1;
                        $needs_data['claim_status'] = 1;
                        $needs_data['created'] = time();
                        $needs_data['updated'] = time();
                        $needs_id = $this->mneeds->create($needs_data);
                        if($needs_id){
                            $this->vdata['returnCode']   = '200';
                            $this->vdata['returnInfo'] = '发布成功';
                            $this->vdata['secure']     = JSON_SECURE;
                            $this->vdata['content'] = array('need_id'=>$needs_id,'pid'=>$pid);
                        }else{
                            $this->vdata['returnCode']   = '200';
                            $this->vdata['returnInfo'] = '发布失败';
                            $this->vdata['secure']     = JSON_SECURE;
                            $this->vdata['content']= array();
                        }
                    }
                }
            }else{
                $this->vdata['returnCode']   = '250';
                $this->vdata['returnInfo'] = '无发布权限';
                $this->vdata['secure']     = JSON_SECURE;
                $this->vdata['content']= array();
            }
        }
        $this->_send_json($this->vdata);
    }


    /**
     * 支付押金页面
     */
    public function pay_info(){
        $need_id = $this->input->post('id');
        if(!$need_id){
            $this->vdata['returnCode']   = '250';
            $this->vdata['returnInfo'] = '请求失败';
            $this->vdata['secure']     = JSON_SECURE;
            $this->vdata['content']= array();
        }else{
            $need_info = $this->mneeds->get_one(array('id'=>$need_id),'id,margin,intro,order_sn,min_money,max_money');
            if(empty($need_info)){
                $this->vdata['returnCode']   = '250';
                $this->vdata['returnInfo'] = '悬赏不存在';
                $this->vdata['secure']     = JSON_SECURE;
                $this->vdata['content']= array();
            }else{
                $balance = $this->userinfo['balance'];
                if($balance < $need_info['margin']){
                    $need_info['is_empty'] = 0;     //余额不足
                    $need_info['balance'] = $balance;
                    $this->vdata['returnCode']   = '200';
                    $this->vdata['returnInfo'] = '操作成功';
                    $this->vdata['secure']     = JSON_SECURE;
                    $this->vdata['content']= $need_info;
                }else{
                    $need_info['is_empty'] = 1;     //余额充足
                    $need_info['balance'] = $balance;
                    $this->vdata['returnCode']   = '200';
                    $this->vdata['returnInfo'] = '操作成功';
                    $this->vdata['secure']     = JSON_SECURE;
                    $this->vdata['content']= $need_info;
                }
            }
        }
        $this->_send_json($this->vdata);
    }


    /**
     * 支付处理（余额支付）
     */
    public function balance_payment(){
        $need_id = $this->input->post('id');
        $method = $this->input->post('method');
        if(!$need_id){
            $this->vdata['returnCode']   = '250';
            $this->vdata['returnInfo'] = '请求失败';
            $this->vdata['secure']     = JSON_SECURE;
            $this->vdata['content']= array();
        }elseif(!$method){
            $this->vdata['returnCode']   = '250';
            $this->vdata['returnInfo'] = '请选择支付方式';
            $this->vdata['secure']     = JSON_SECURE;
            $this->vdata['content']= array();
        }else{
            if($method==3){
                //判断该需求是否已经支付过了  不可重复支付
                $needs_info = $this->mneeds->get_one(array('id'=>$need_id),'id,margin,intro,order_sn,claim_status');
                if(empty($needs_info)){
                    $this->vdata['returnCode']   = '250';
                    $this->vdata['returnInfo'] = '悬赏不存在';
                    $this->vdata['secure']     = JSON_SECURE;
                    $this->vdata['content']= array();
                }else{
                    if($needs_info['claim_status']==1){
                        $this->vdata['returnCode']   = '250';
                        $this->vdata['returnInfo'] = '已经支付过了';
                        $this->vdata['secure']     = JSON_SECURE;
                        $this->vdata['content']= array();
                    }else{
                        //使用余额支付 查询余额是否充足
                        $balance = $this->userinfo['balance'];
                        $money = $needs_info['margin'];
                        if($balance >=$money){
                            $s_balance = $balance-$money;   //扣除余额（悬赏支出押金）
                            //生成交易单号
                            $payment_sn = ordernum_time('',true);
                            $pay_time = time();
                            //悬赏支出
                            $balance_data_out = array(
                                'uid'=>$this->userinfo['id'],
                                'type'=>3,    //悬赏发布押金
                                'need_id'=>$need_id,
                                'title'=>$needs_info['intro'],
                                'money'=>$money,
                                'status'=>2,   //冻结
                                'pay_ways'=>3,
                                'pay_time'=>$pay_time,
                                'created_at'=>time(),
                                'rid'=>0,
                                'payment_sn'=>$payment_sn,
                                'pay_code'=>$needs_info['order_sn'],
                            );
                            //获取后台的倒计时设置时间
                            $count_down = $this->mcount_down->get_one(array('id'=>1),'hours');
                            $countdown = $pay_time + $count_down['hours']*3600;
                            if($this->mbalance->create($balance_data_out)){
                                //更新账户余额
                                $this->maccount->update(array('balance'=>$s_balance),array('id'=>$this->userinfo['id']));
                                //更新需求订单的状态
                                $this->mneeds->update(array('payment_sn'=>$payment_sn,'method'=>3,'status'=>1,'countdown'=>$countdown,'pay_time'=>$pay_time,'claim_status'=>1,'updated'=>time()),array('id'=>$need_id));
                                $this->vdata['returnCode'] = '200';
                                $this->vdata['returnInfo'] = '余额成功付款';
                                $this->vdata['secure'] = JSON_SECURE;
                                $this->vdata['content'] = array('need_id'=>$need_id,'order_sn'=>$needs_info['order_sn'],'payment_sn'=>$payment_sn);
                            }else{
                                $this->vdata['returnCode']   = '250';
                                $this->vdata['returnInfo'] = '余额付款失败';
                                $this->vdata['secure']     = JSON_SECURE;
                                $this->vdata['content']= array();
                            }

                        }else{
                            $this->vdata['returnCode'] = '250';
                            $this->vdata['returnInfo'] = '余额不足';
                            $this->vdata['content'] = '';
                        }
                    }
                }
            }
        }
        $this->_send_json($this->vdata);
    }


    /**
     * 我的需求（全部、认领的、我发布的）
     */
    public function my_needs(){
        $cate = $this->input->post('cate');
        $uid = $this->userinfo['id'];
        if($cate==0){
            //全部
            $query = $this->db->select('need_id')
                ->from("boc_claim")
                ->where(array('uid'=>$uid,'is_deleted'=>0))
                ->get();
            $need_id = $query->result_array();
            $need_ids = array();
            if(!empty($need_id)){
                foreach ($need_id as $val) {
                    $need_ids[] = $val['need_id'];
                }
                $where = array('in' => array('id', $need_ids), 'is_deleted' => 0);
                $where11 = array('or' => array('uid'=>$uid), 'is_deleted' => 0);
                $start = $this->input->post('page');
                $limit = 10;
                $start = $limit*($start-1);
                $filed = "id,uid,min_money,max_money,order_sn,cate_id,type,created,intro,end_time,photos,method,status,margin,claim_money,countdown,expire_time,pay_time,is_delay,is_again,views,claim_nums,claim_status";
                $needs_result = $this->db->select($filed)
                    ->from("boc_needs")
                    ->where($where)
                    ->where($where11)
                    ->order_by('created','desc')
                    ->limit($limit,$start)
                    ->get();
                $needs = $needs_result->result_array();
            }else{
                $start = $this->input->post('page');
                $limit = 10;
                $start = $limit*($start-1);
                $filed = "id,uid,min_money,max_money,order_sn,cate_id,type,created,intro,end_time,photos,method,status,margin,claim_money,countdown,expire_time,pay_time,is_delay,is_again,views,claim_nums,claim_status";
                $needs_result = $this->db->select($filed)
                    ->from("boc_needs")
                    ->where(array('uid'=>$uid,'is_deleted'=>0))
                    ->order_by('created','desc')
                    ->limit($limit,$start)
                    ->get();
                $needs = $needs_result->result_array();
            }
        }elseif($cate==1){
            //认领的
            $query = $this->db->select('need_id')
                ->from("boc_claim")
                ->where(array('uid'=>$uid))
                ->get();
            $need_id = $query->result_array();
            $need_ids = array();
            if(!empty($need_id)){
                foreach ($need_id as $val) {
                    $need_ids[] = $val['need_id'];
                }
                $start = $this->input->post('page');
                $limit = 10;
                $start = $limit*($start-1);
                $filed = "id,uid,min_money,max_money,order_sn,cate_id,type,created,intro,end_time,photos,method,status,margin,claim_money,countdown,expire_time,pay_time,is_delay,is_again,views,claim_nums,claim_status";
                $needs_result = $this->db->select($filed)
                    ->from("boc_needs")
                    ->where(array('in'=>array('id',$need_ids),'is_deleted'=>0))
                    ->order_by('created','desc')
                    ->limit($limit,$start)
                    ->get();
                $needs = $needs_result->result_array();
            }else{
                $needs = array();
            }

        }elseif($cate==2){
            //我发布的
            $start = $this->input->post('page');
            $limit = 10;
            $start = $limit*($start-1);
            $filed = "id,uid,min_money,max_money,order_sn,cate_id,type,created,intro,end_time,photos,method,status,margin,claim_money,countdown,expire_time,pay_time,is_delay,is_again,views,claim_nums,claim_status";
            $needs_result = $this->db->select($filed)
                ->from("boc_needs")
                ->where(array('uid'=>$uid,'is_deleted'=>0))
                ->order_by('created','desc')
                ->limit($limit,$start)
                ->get();
            $needs = $needs_result->result_array();
        }
        if(empty($needs)){
            $this->vdata['returnCode']   = '200';
            $this->vdata['returnInfo'] = '获取成功';
            $this->vdata['secure']     = JSON_SECURE;
            $this->vdata['content']= array();
        }else{
            foreach($needs as $key=>$val){
                $cate = $this->mcategory->get_one(array('id'=>$val['cate_id']),'title');
                //认领情况
                $claim_info = $this->mclaim->get_one(array('uid'=>$this->userinfo['id'],'need_id'=>$val['id']),'is_assign');
                if(empty($claim_info)){
                    $needs[$key]['is_claim'] = 0;
                }else{
                    $needs[$key]['is_claim'] = 1;
                    if($claim_info['is_assign']==1){
                        $needs[$key]['is_assign'] = 1;         //已指派
                    }else{
                        $needs[$key]['is_assign'] = 0;         //未指派
                    }
                }
                $needs[$key]['category'] = $cate['title'];
                $needs[$key]['intro'] = content_br($val['intro']);
                $needs[$key]['cre_time'] = date('m-d H:i',$val['created']);
                $time = time();
                $needs[$key]['now_time'] = $time;
            }
            $this->vdata['returnCode']   = '200';
            $this->vdata['returnInfo'] = '获取成功';
            $this->vdata['secure']     = JSON_SECURE;
            $this->vdata['content']= $needs;
        }
        $this->_send_json($this->vdata);
    }

    /**
     * 市场需求(默认显示我关注的、市场所有)
     */
    public function market_needs(){
        $cate = $this->input->post('cate');
        $uid = $this->userinfo['id'];
        $cates= explode(',',$this->input->post('cate_id'));
        $category = array();
        foreach($cates as $ves){
            if($ves!=''){
                $category[] = $ves;
            }
        }
        if($cate==1){
            //我关注的，我关注的人发布的需求
            $query = $this->db->select('rid')
                ->from("boc_concern_fans")
                ->where(array('uid'=>$uid,'is_deleted'=>1))
                ->get();
            $uids = $query->result_array();
            $uides = array();
            if(!empty($uids)){
                foreach ($uids as $val) {
                    $uides[] = $val['rid'];
                }
                $start = $this->input->post('page');
                $limit = 10;
                $start = $limit*($start-1);
                $filed = "id,uid,min_money,max_money,order_sn,cate_id,type,created,intro,end_time,photos,method,status,margin,claim_money,countdown,expire_time,pay_time,is_delay,is_again,views,claim_nums,claim_status";
                if(!empty($category)){
                    if($category[0]==30 && count($category)==1){
                        $type =1;    //筛选所有的悬赏
                        $needs_result = $this->db->select($filed)
                            ->from("boc_needs")
                            ->where(array('in'=>array('uid',$uides),'type'=>$type,'claim_status'=>1,'status'=>1,'is_deleted'=>0))
                            ->order_by('created','desc')
                            ->limit($limit,$start)
                            ->get();
                    }else{
                        $needs_result = $this->db->select($filed)
                            ->from("boc_needs")
                            ->where(array('in'=>array('uid',$uides),'in 2'=>array('cate_id',$category),'claim_status'=>1,'status'=>1,'is_deleted'=>0))
                            ->order_by('created','desc')
                            ->limit($limit,$start)
                            ->get();
                    }
                }else{
                    $needs_result = $this->db->select($filed)
                        ->from("boc_needs")
                        ->where(array('in'=>array('uid',$uides),'claim_status'=>1,'status'=>1,'is_deleted'=>0))
                        ->order_by('created','desc')
                        ->limit($limit,$start)
                        ->get();
                }

                $needs = $needs_result->result_array();
            }else{
                $needs = array();
            }

        }elseif($cate==2){
            if(!empty($category)){
                if($category[0]==30 && count($category)==1){
                    $type =1;    //筛选所有的悬赏
                    $start = $this->input->post('page');
                    $limit = 10;
                    $start = $limit*($start-1);
                    $filed = "id,uid,min_money,max_money,order_sn,cate_id,type,created,intro,end_time,photos,method,status,margin,claim_money,countdown,expire_time,pay_time,is_delay,is_again,views,claim_nums,claim_status";
                    $needs_result = $this->db->select($filed)
                        ->from("boc_needs")
                        ->where(array('claim_status'=>1,'status'=>1,'type'=>$type,'is_deleted'=>0))
//                        ->order_by('type asc,countdown asc,created desc')
                        ->order_by('created','desc')
                        ->limit($limit,$start)
                        ->get();
                }else{
                    $start = $this->input->post('page');
                    $limit = 10;
                    $start = $limit*($start-1);
                    $filed = "id,uid,min_money,max_money,order_sn,cate_id,type,created,intro,end_time,photos,method,status,margin,claim_money,countdown,expire_time,pay_time,is_delay,is_again,views,claim_nums,claim_status";
                    $needs_result = $this->db->select($filed)
                        ->from("boc_needs")
                        ->where(array('claim_status'=>1,'status'=>1,'in'=>array('cate_id',$category),'is_deleted'=>0))
//                        ->order_by('type asc,countdown asc,created desc')
                        ->order_by('created','desc')
                        ->limit($limit,$start)
                        ->get();
                }
            }else{
                $start = $this->input->post('page');
                $limit = 10;
                $start = $limit*($start-1);
                $filed = "id,uid,min_money,max_money,order_sn,cate_id,type,created,intro,end_time,photos,method,status,margin,claim_money,countdown,expire_time,pay_time,is_delay,is_again,views,claim_nums,claim_status";
                $needs_result = $this->db->select($filed)
                    ->from("boc_needs")
                    ->where(array('claim_status'=>1,'status'=>1,'is_deleted'=>0))
//                    ->order_by('type asc,countdown asc,created desc')
                    ->order_by('created','desc')
                    ->limit($limit,$start)
                    ->get();
            }
            $needs = $needs_result->result_array();
        }
        if(empty($needs)){
            $this->vdata['returnCode']   = '200';
            $this->vdata['returnInfo'] = '获取成功';
            $this->vdata['secure']     = JSON_SECURE;
            $this->vdata['content']= array();
        }else{
            foreach($needs as $key=>$val){
                //判断是不是自己的
                if($val['uid']==$this->userinfo['id']){
                    $needs[$key]['is_me'] = 1;
                }else{
                    $needs[$key]['is_me'] = 0;
                }
                //判断是不是已经认领
                $claim_info = $this->mclaim->get_one(array('uid'=>$this->userinfo['id'],'need_id'=>$val['id']),'is_assign');
                if(empty($claim_info)){
                    $needs[$key]['is_claim'] = 0;
                }else{
                    $needs[$key]['is_claim'] = 1;
                    if($claim_info['is_assign']==1){
                        $needs[$key]['is_assign'] = 1;         //已指派
                    }else{
                        $needs[$key]['is_assign'] = 0;         //未指派
                    }
                }
                $cate = $this->mcategory->get_one(array('id'=>$val['cate_id']),'title');
                $needs[$key]['category'] = $cate['title'];
                $needs[$key]['intro'] = content_br($val['intro']);
                $needs[$key]['cre_time'] = date('m-d H:i',$val['created']);
                $time = time();
                $needs[$key]['now_time'] = $time;
            }
            $this->vdata['returnCode']   = '200';
            $this->vdata['returnInfo'] = '获取成功';
            $this->vdata['secure']     = JSON_SECURE;
            $this->vdata['content']= $needs;
        }
        $this->_send_json($this->vdata);
    }

    /**
     * 悬赏详情(发布方和认领方)
     */
    public function need_detail(){
        $need_id = $this->input->post('id');
        if(!$need_id){
            $this->vdata['returnCode']   = '250';
            $this->vdata['returnInfo'] = '请求失败';
            $this->vdata['secure']     = JSON_SECURE;
            $this->vdata['content']= array();
        }else{
            $need_info = $this->mneeds->get_one(array('id'=>$need_id,'is_deleted'=>0));
            if(empty($need_info)){
                $this->vdata['returnCode']   = '250';
                $this->vdata['returnInfo'] = '请求失败';
                $this->vdata['secure']     = JSON_SECURE;
                $this->vdata['content']= array();
            }else{
                $uid = $this->userinfo['id'];
                $user_info = $this->maccount->get_one(array('id'=>$need_info['uid']));
                $info['uname'] = $user_info['uname'];  //发布人姓名
                $info['uid'] = $user_info['id'];  //发布人姓名
                $photo = $this->mupload->get_one(array('id'=>$user_info['photo']));
                if(!empty($photo)){
                    $info['headimg'] = UPLOAD_URL.$photo['url'];  //发布人头像地址
                }else{
                    $info['headimg'] = '';
                }
                $info['cre_time'] = date('m-d H:i',$need_info['created']);
                $cate = $this->mcategory->get_one(array('id'=>$need_info['cate_id']));
                $info['category'] = $cate['title'];         //分类
                $info['intro'] = content_br($need_info['intro']);       //简介
                $info['type'] = $need_info['type'];         //类型（1悬赏2路演3需求对接）
                if($need_info['type']==1){
                    $info['min_money'] = $need_info['min_money'];
                    $info['max_money'] = $need_info['max_money'];
                    $info['margin'] = $need_info['margin'];
                    $info['countdown'] = $need_info['countdown'];
                    $info['expire_time'] = $need_info['expire_time'];
                }elseif($need_info['type']==2){
                    $info['countdown'] = $need_info['end_time'];
                }
                $need_photo = array();
                if($need_info['photos']!=''){
                    $c_photos = explode(',',$need_info['photos']);
                    foreach($c_photos as $c_photo){
                        $img = $this->mupload->get_one(array('id'=>$c_photo));
                        if(!empty($img)){
                            $need_photo[] = UPLOAD_URL.$img['url'];
                        }
                    }
                }
                $info['imgs'] = $need_photo;       //发布的图片地址
                $info['status'] = $need_info['status'];   //0待支付1成功2失败3取消
                $info['views'] = $need_info['views'];    //浏览量
                $info['claim_nums'] = $need_info['claim_nums'];  //认领数、报名数
                $info['claim_status'] = $need_info['claim_status'];  //悬赏状态
                $info['cancel_status'] = $need_info['cancel_status'];  //撤销状态
                $info['cancel_time'] = $need_info['cancel_time'];  //撤销时间
                $info['arbitrate'] = $need_info['arbitrate'];  //是否仲裁
                $info['c_arbitrate'] = $need_info['c_arbitrate'];  //是否仲裁（认领方）
                $info['balance'] = $this->userinfo['balance'];  //余额
                $time = time();
                $info['now_time'] = $time;
                if($need_info['uid']==$uid){
                    $info['is_can'] = 1;
                }else{
                    $info['is_can'] = 0;
                }
                //查询申领佣金信息
                $claim_info = $this->mclaim->get_one(array('need_id'=>$need_id,'is_assign'=>1));
                if(!empty($claim_info)){
                    $need_apply = $this->mneedapply->get_one(array('uid'=>$claim_info['uid'],'claim_id'=>$claim_info['id'],'need_id'=>$need_id));
                    if(empty($need_apply)){
                        $info['c_arbitrate_info'] = 0;
                    }else{
                        $create_time = $need_apply['created'] + 24*3600;
                        $now_time = time();
                        if($create_time < $now_time){
                            $info['c_arbitrate_info'] = 1;
                        }else{
                            $info['c_arbitrate_info'] = 0;
                        }
                    }
                }else{
                    $info['c_arbitrate_info'] = 0;
                }
                //查询撤销情况
                if($need_info['uid']==$uid){
                    $info['is_can'] = 1;
                    $last_cancel = $this->userinfo['last_cancel'];
                    if($last_cancel!=0){
                        if($last_cancel+90*24*3600 < time()){
                            //超过三个月则可发布和撤销的权限
                            //查看当月已经有几条撤销记录
                            $start_time = strtotime(date('Y-m-01'));
                            $end_time = strtotime(date('Y-m-d', strtotime(date('Y-m-01', strtotime(date('Y-m-01'))) . ' +1 month -1 day')))+24*3600-1;
                            //指派中撤销次数  一个月3次机会
                            $claim_res = $this->db->query("select * from boc_needs where cancel_time > $start_time and cancel_time < $end_time and cancel_status=2 and uid=$uid")->result_array();
                            $info['claim_counts'] = count($claim_res);
                            $info['is_cancel'] = 1;
                        }else{
                            $info['is_cancel'] = 0;
                        }
                    }else{
                        //查看当月已经有几条撤销记录
                        $start_time = strtotime(date('Y-m-01'));
                        $end_time = strtotime(date('Y-m-d', strtotime(date('Y-m-01', strtotime(date('Y-m-01'))) . ' +1 month -1 day')))+24*3600-1;
                        $claim_res = $this->db->query("select * from boc_needs where cancel_time > $start_time and cancel_time < $end_time and cancel_status=2 and uid=$uid")->result_array();
                        $info['claim_counts'] = count($claim_res);
                        $info['is_cancel'] = 1;
                    }
                }else{
                    $info['is_can'] = 0;
                }
                //更新浏览量
                $this->mneeds->set($need_id,array('views','views + 1'));
                $this->vdata['returnCode']   = '200';
                $this->vdata['returnInfo'] = '获取成功';
                $this->vdata['secure']     = JSON_SECURE;
                $this->vdata['content']= $info;
            }
        }
        $this->_send_json($this->vdata);
    }
    /**
     * 悬赏详情(发布方和认领方)
     */
    public function need_detailh5(){
        $need_id = $this->input->post('id');
        if(!$need_id){
            $this->vdata['returnCode']   = '250';
            $this->vdata['returnInfo'] = '请求失败';
            $this->vdata['secure']     = JSON_SECURE;
            $this->vdata['content']= array();
        }else{
            $need_info = $this->mneeds->get_one(array('id' => $need_id));
            if(empty($need_info)){
                $this->vdata['returnCode']   = '250';
                $this->vdata['returnInfo'] = '请求失败';
                $this->vdata['secure']     = JSON_SECURE;
                $this->vdata['content']= array();
            }else{
                $uid = $this->userinfo['id'];
                $user_info = $this->maccount->get_one(array('id'=>$need_info['uid']));
                $info['uname'] = $user_info['uname'];  //发布人姓名
                $info['uid'] = $user_info['id'];  //发布人姓名
                $photo = $this->mupload->get_one(array('id'=>$user_info['photo']));
                if(!empty($photo)){
                    $info['headimg'] = UPLOAD_URL.$photo['url'];  //发布人头像地址
                }else{
                    $info['headimg'] = '';
                }
                $info['cre_time'] = date('m-d H:i',$need_info['created']);
                $cate = $this->mcategory->get_one(array('id'=>$need_info['cate_id']));
                $info['category'] = $cate['title'];         //分类
                $info['intro'] = content_br($need_info['intro']);       //简介
                $info['type'] = $need_info['type'];         //类型（1悬赏2路演3需求对接）
                if($need_info['type']==1){
                    $info['min_money'] = $need_info['min_money'];
                    $info['max_money'] = $need_info['max_money'];
                    $info['margin'] = $need_info['margin'];
                    $info['countdown'] = $need_info['countdown'];
                    $info['expire_time'] = $need_info['expire_time'];
                }elseif($need_info['type']==2){
                    $info['countdown'] = $need_info['end_time'];
                }
                $need_photo = array();
                if($need_info['photos']!=''){
                    $c_photos = explode(',',$need_info['photos']);
                    foreach($c_photos as $c_photo){
                        $img = $this->mupload->get_one(array('id'=>$c_photo));
                        if(!empty($img)){
                            $need_photo[] = UPLOAD_URL.$img['url'];
                        }
                    }
                }
                $info['imgs'] = $need_photo;       //发布的图片地址
                $info['status'] = $need_info['status'];   //0待支付1成功2失败3取消
                $info['views'] = $need_info['views'];    //浏览量
                $info['claim_nums'] = $need_info['claim_nums'];  //认领数、报名数
                $info['claim_status'] = $need_info['claim_status'];  //悬赏状态
                $info['cancel_status'] = $need_info['cancel_status'];  //撤销状态
                $info['cancel_time'] = $need_info['cancel_time'];  //撤销时间
                $info['arbitrate'] = $need_info['arbitrate'];  //是否仲裁
                $info['c_arbitrate'] = $need_info['c_arbitrate'];  //是否仲裁（认领方）
                $info['balance'] = $this->userinfo['balance'];  //余额
                $time = time();
                $info['now_time'] = $time;
                if($need_info['uid']==$uid){
                    $info['is_can'] = 1;
                    $last_cancel = $this->userinfo['last_cancel'];
                    if($last_cancel!=0){
                        if($last_cancel+90*24*3600 < time()){
                            //超过三个月则可发布和撤销的权限
                            //查看当月已经有几条撤销记录
                            $start_time = strtotime(date('Y-m-01'));
                            $end_time = strtotime(date('Y-m-d', strtotime(date('Y-m-01', strtotime(date('Y-m-01'))) . ' +1 month -1 day')))+24*3600-1;
                            //指派中撤销次数  一个月3次机会
                            $claim_res = $this->db->query("select * from boc_needs where cancel_time > $start_time and cancel_time < $end_time and cancel_status=2 and uid=$uid")->result_array();
                            $info['claim_counts'] = count($claim_res);
                            $info['is_cancel'] = 1;
                        }else{
                            $info['is_cancel'] = 0;
                        }
                    }else{
                        //查看当月已经有几条撤销记录
                        $start_time = strtotime(date('Y-m-01'));
                        $end_time = strtotime(date('Y-m-d', strtotime(date('Y-m-01', strtotime(date('Y-m-01'))) . ' +1 month -1 day')))+24*3600-1;
                        $claim_res = $this->db->query("select * from boc_needs where cancel_time > $start_time and cancel_time < $end_time and cancel_status=2 and uid=$uid")->result_array();
                        $info['claim_counts'] = count($claim_res);
                        $info['is_cancel'] = 1;
                    }
                }else{
                    $info['is_can'] = 0;
                }
                //查询申领佣金信息
                $claim_info = $this->mclaim->get_one(array('need_id'=>$need_id,'is_assign'=>1));
                if(!empty($claim_info)){
                    $need_apply = $this->mneedapply->get_one(array('uid'=>$claim_info['uid'],'claim_id'=>$claim_info['id'],'need_id'=>$need_id));
                    if(empty($need_apply)){
                        $info['c_arbitrate_info'] = 0;
                    }else{
                        $create_time = $need_apply['created'] + 24*3600;
                        $now_time = time();
                        if($create_time < $now_time){
                            $info['c_arbitrate_info'] = 1;
                        }else{
                            $info['c_arbitrate_info'] = 0;
                        }
                    }
                }else{
                    $info['c_arbitrate_info'] = 0;
                }
                //更新浏览量
                $this->mneeds->set($need_id,array('views','views + 1'));
                $this->vdata['returnCode']   = '200';
                $this->vdata['returnInfo'] = '获取成功';
                $this->vdata['secure']     = JSON_SECURE;
                $this->vdata['content']= $info;
            }
        }
        $this->_send_json($this->vdata);
    }
    /**
     * 需求的认领人数和路演活动的报名人数统计(下拉加载)
     */
    public function claim_list(){
        $need_id = $this->input->post('need_id');
        if(!$need_id){
            $this->vdata['returnCode']   = '250';
            $this->vdata['returnInfo'] = '请求失败';
            $this->vdata['secure']     = JSON_SECURE;
            $this->vdata['content']= array();
        }else{
            $need_info = $this->mneeds->get_one(array('id'=>$need_id));
            if(empty($need_info)){
                $this->vdata['returnCode']   = '250';
                $this->vdata['returnInfo'] = '请求失败';
                $this->vdata['secure']     = JSON_SECURE;
                $this->vdata['content']= array();
            }else{
                if($need_info['uid']==$this->userinfo['id'] || $need_info['type']==2){
                    //发布方显示
                    $start = $this->input->post('page');
                    $limit = 10;
                    $start = $limit*($start-1);
                    $filed = "a.id,a.money,a.created_time,a.is_assign,a.stars as star,b.uname,b.id as uid,b.claims,b.stars,b.last_cancel,c.url";
                    $result = $this->db->select($filed)
                        ->from("boc_claim as a")
                        ->join('boc_account as b','a.uid=b.id','left')
                        ->join('boc_upload as c','b.photo=c.id','left')
                        ->where(array('a.need_id'=>$need_id))
                        ->order_by('a.created_time desc,a.is_assign desc')
                        ->limit($limit,$start)
                        ->get();
                    $claims = $result->result_array();
                }else{
                    //认领方显示只显示自己的
                    $filed = "a.id,a.money,a.created_time,a.is_assign,a.stars as star,b.uname,b.id as uid,b.claims,b.stars,b.last_cancel,c.url";
                    $result = $this->db->select($filed)
                        ->from("boc_claim as a")
                        ->join('boc_account as b','a.uid=b.id','left')
                        ->join('boc_upload as c','b.photo=c.id','left')
                        ->where(array('a.need_id'=>$need_id,'a.uid'=>$this->userinfo['id']))
                        ->get();
                    $claims = $result->result_array();
                }
                if(!empty($claims)){
                    foreach($claims as $kk=>$vv){
                        $claims[$kk]['cre_time'] = date('m-d H:i',$vv['created_time']);
                        $claims[$kk]['imgurl'] = UPLOAD_URL.$vv['url'];
                    }
                }
                $this->vdata['returnCode']   = '200';
                $this->vdata['returnInfo'] = '获取成功';
                $this->vdata['secure']     = JSON_SECURE;
                $this->vdata['content']= $claims;
            }
        }
        $this->_send_json($this->vdata);
    }


    /**
     * 认领和报名（非发布方操作）
     */
    public function claim_needs(){
        $need_id = $this->input->post('need_id');
        if(!$need_id){
            $this->vdata['returnCode']   = '250';
            $this->vdata['returnInfo'] = '请求失败';
            $this->vdata['secure']     = JSON_SECURE;
            $this->vdata['content']= array();
        }else{
            $need_info = $this->mneeds->get_one(array('id'=>$need_id,'status'=>1,'claim_status'=>1));
            if(empty($need_info)){
                $this->vdata['returnCode']   = '250';
                $this->vdata['returnInfo'] = '请求失败';
                $this->vdata['secure']     = JSON_SECURE;
                $this->vdata['content']= array();
            }else{
                //优先判断是不是自己发布的
                if($need_info['uid']==$this->userinfo['id']){
                    $this->vdata['returnCode']   = '250';
                    $this->vdata['returnInfo'] = '非法请求';
                    $this->vdata['secure']     = JSON_SECURE;
                    $this->vdata['content']= array();
                }else{
                    //查询是否已经认领或者报名过
                    $claim_info = $this->mclaim->get_one(array('uid'=>$this->userinfo['id'],'need_id'=>$need_id));
                    if(empty($claim_info)){
                        if($need_info['type']==2){
                            $claim_data = array(
                                'uid'=>$this->userinfo['id'],
                                'need_id'=>$need_id,
                                'created_time'=>time()
                            );
                            $claim_id = $this->mclaim->create($claim_data);
                            if($claim_id){
                                //更新需求的报名数
                                /*******添加推送板块**********/
                                $to_uid = $need_info['uid'];
                                $uname = $this->userinfo['uname'];
                                $t_type = 4;
                                $content = $uname.'报名了您的活动';
                                getui_push($to_uid,$t_type,$need_id,$content);
                                $this->mneeds->set($need_id,array('claim_nums','claim_nums + 1'));
                                $this->vdata['returnCode']   = '200';
                                $this->vdata['returnInfo'] = '报名成功';
                                $this->vdata['secure']     = JSON_SECURE;
                                $this->vdata['content']= array('id'=>$claim_id);
                            }else{
                                $this->vdata['returnCode']   = '250';
                                $this->vdata['returnInfo'] = '报名失败';
                                $this->vdata['secure']     = JSON_SECURE;
                                $this->vdata['content']= array();
                            }
                        }elseif($need_info['type']==1){
                            $money = $this->input->post('money');
                            if(!is_positive_number($money)){
                                $this->vdata['returnCode']   = '250';
                                $this->vdata['returnInfo'] = '请输入报价';
                                $this->vdata['secure']     = JSON_SECURE;
                                $this->vdata['content']= array();
                            }else{
                                $claim_data = array(
                                    'uid'=>$this->userinfo['id'],
                                    'need_id'=>$need_id,
                                    'money'=>$money,
                                    'created_time'=>time(),
                                    'update_time'=>time()
                                );
                                $claim_id = $this->mclaim->create($claim_data);
                                if($claim_id){
                                    //更新需求的认领数
                                    /*******添加推送板块**********/
                                    $to_uid = $need_info['uid'];
                                    $uname = $this->userinfo['uname'];
                                    $t_type = 1;
                                    $content = $uname.'认领了您发布的需求';
                                    getui_push($to_uid,$t_type,$need_id,$content);
                                    $this->mneeds->set($need_id,array('claim_nums','claim_nums + 1'));
                                    $this->vdata['returnCode']   = '200';
                                    $this->vdata['returnInfo'] = '认领成功';
                                    $this->vdata['secure']     = JSON_SECURE;
                                    $this->vdata['content']= array('id'=>$claim_id);
                                }else{
                                    $this->vdata['returnCode']   = '250';
                                    $this->vdata['returnInfo'] = '认领失败';
                                    $this->vdata['secure']     = JSON_SECURE;
                                    $this->vdata['content']= array();
                                }
                            }
                        }
                    }else{
                        $this->vdata['returnCode']   = '250';
                        $this->vdata['returnInfo'] = '不可重复操作';
                        $this->vdata['secure']     = JSON_SECURE;
                        $this->vdata['content']= array();
                    }
                }
            }
        }
        $this->_send_json($this->vdata);
    }

    /**
     * 指派（发布方操作）只有悬赏任务才有该操作
     */
    public function assign_needs(){
        $claim_id = $this->input->post('claim_id');
        if(!$claim_id){
            $this->vdata['returnCode']   = '250';
            $this->vdata['returnInfo'] = '请求失败';
            $this->vdata['secure']     = JSON_SECURE;
            $this->vdata['content']= array();
        }else{
            $claim_info = $this->mclaim->get_one(array('id'=>$claim_id));
            if(empty($claim_info)){
                $this->vdata['returnCode']   = '250';
                $this->vdata['returnInfo'] = '无此记录';
                $this->vdata['secure']     = JSON_SECURE;
                $this->vdata['content']= array();
            }else{
                //查询需求的详细信息
                $need_info = $this->mneeds->get_one(array('id'=>$claim_info['need_id']));
                if($need_info['claim_status']==1 || $need_info['claim_status']==2){
                    if($need_info['uid']==$this->userinfo['id']){
                        //如果议价小于发布押金直接修改需求订单状态，并将其指派
                        if($claim_info['money'] <= $need_info['margin']){
                            $this->mneeds->update(array('claim_status'=>3,'claim_money'=>$claim_info['money']),array('id'=>$need_info['id']));
                            $this->mclaim->update(array('is_assign'=>1),array('id'=>$claim_id));
                            /*******添加推送板块**********/
                            $to_uid = $claim_info['uid'];
                            $uname = $this->userinfo['uname'];
                            $t_type = 1;
                            $content = '您已被'.$uname.'指派任务';
                            getui_push($to_uid,$t_type,$claim_info['need_id'],$content);
                            $this->vdata['returnCode']   = '200';
                            $this->vdata['returnInfo'] = '指派成功';
                            $this->vdata['secure']     = JSON_SECURE;
                            $this->vdata['content']= array();
                        }elseif($claim_info['money'] > $need_info['margin']){
                            //查看差价是否大于账户余额
                            $surpose_money = $claim_info['money']-$need_info['margin'];  //差价
                            $balance = $this->userinfo['balance'];     //账户余额
                            if($surpose_money <= $balance){             //账户余额充足
                                //确认指派的操作 明细记录，更新账户余额，修改状态
                                //生成交易单号
                                $payment_sn = ordernum_time('',true);
                                $pay_code = get_order_sn('boc_need_order','E');
                                $pay_time = time();
                                $s_balance = $balance-$surpose_money;   //扣除余额（悬赏支出补差价）
                                //差价支出
                                $balance_data_out = array(
                                    'uid'=>$this->userinfo['id'],
                                    'type'=>4,    //指派补差价
                                    'need_id'=>$need_info['id'],
                                    'title'=>$need_info['intro'],
                                    'money'=>$surpose_money,
                                    'status'=>7,   //差价冻结
                                    'pay_ways'=>3,  //余额支付
                                    'pay_time'=>$pay_time,
                                    'created_at'=>time(),
                                    'rid'=>0,
                                    'payment_sn'=>$payment_sn,
                                    'pay_code'=>$pay_code,
                                );
                                //生成一条补差价订单
                                $need_order = array(
                                    'uid'=>$this->userinfo['id'],
                                    'type'=>3,
                                    'money'=>$surpose_money,
                                    'claim_id'=>$claim_id,
                                    'need_id'=>$need_info['id'],
                                    'payment_sn'=>$payment_sn,
                                    'pay_code'=>$pay_code,
                                    'created'=>time(),
                                    'pay_time'=>time(),
                                    'status'=>1              //支付成功
                                );
                                $need_order_id = $this->mneedorder->create($need_order);
                                $balance_data_out_id = $this->mbalance->create($balance_data_out);
                                if($need_order_id && $balance_data_out_id){
                                    //更新账户余额
                                    $this->mneeds->update(array('claim_status'=>3,'claim_money'=>$claim_info['money']),array('id'=>$need_info['id']));
                                    $this->mclaim->update(array('is_assign'=>1,'update_time'=>time()),array('id'=>$claim_id));
                                    $this->maccount->update(array('balance'=>$s_balance),array('id'=>$this->userinfo['id']));
                                    /*******添加推送板块**********/
                                    $to_uid = $claim_info['uid'];
                                    $uname = $this->userinfo['uname'];
                                    $t_type = 1;
                                    $content = '您已被'.$uname.'指派任务';
                                    getui_push($to_uid,$t_type,$claim_info['need_id'],$content);
                                    $this->vdata['returnCode'] = '200';
                                    $this->vdata['returnInfo'] = '指派成功';
                                    $this->vdata['secure'] = JSON_SECURE;
                                    $this->vdata['content'] = array();
                                }else{
                                    $this->vdata['returnCode']   = '250';
                                    $this->vdata['returnInfo'] = '余额付款失败';
                                    $this->vdata['secure']     = JSON_SECURE;
                                    $this->vdata['content']= array();
                                }
                            }else{
                                //账户余额不足及充值(待完善)
                                //生成一条补差价订单
                                $c_type = $this->input->post('c_type');   //选择的支付方式  1微信2支付宝
                                $order_sn = get_order_sn('boc_need_order','E');
                                $need_order_in = array(
                                    'uid'=>$this->userinfo['id'],
                                    'type'=>$c_type,
                                    'money'=>$surpose_money,
                                    'claim_id'=>$claim_id,
                                    'need_id'=>$need_info['id'],
                                    'pay_code'=>$order_sn,
                                    'created'=>time(),
                                    'status'=>0
                                );
                                $need_order_id = $this->mneedorder->create($need_order_in);
                                if($need_order_id){
                                    $this->vdata['returnCode'] = '200';
                                    $this->vdata['returnInfo'] = '操作成功';
                                    $this->vdata['secure'] = JSON_SECURE;
                                    $this->vdata['content'] = array('order_id'=>$need_order_id,'ctype'=>$c_type,'order_sn'=>$order_sn,'money'=>$surpose_money);    //补差价订单支付
                                }else{
                                    $this->vdata['returnCode'] = '250';
                                    $this->vdata['returnInfo'] = '操作失败';
                                    $this->vdata['secure'] = JSON_SECURE;
                                    $this->vdata['content'] = array();
                                }
                            }
                        }
                    }else{
                        $this->vdata['returnCode']   = '250';
                        $this->vdata['returnInfo'] = '不可操作';
                        $this->vdata['secure']     = JSON_SECURE;
                        $this->vdata['content']= array();
                    }
                }else{
                    $this->vdata['returnCode']   = '250';
                    $this->vdata['returnInfo'] = '不可操作';
                    $this->vdata['secure']     = JSON_SECURE;
                    $this->vdata['content']= array();
                }
            }
        }
        $this->_send_json($this->vdata);
    }

    /**
     * 申领佣金(只限认领方)
     */
    public function apply_money(){
        $need_id = $this->input->post('need_id');
        if(!$need_id){
            $this->vdata['returnCode']   = '250';
            $this->vdata['returnInfo'] = '请求失败';
            $this->vdata['secure']     = JSON_SECURE;
            $this->vdata['content']= array();
        }else{
            $need_info = $this->mneeds->get_one(array('id'=>$need_id,'status'=>1,'claim_status'=>3));
            if(empty($need_info)){
                $this->vdata['returnCode']   = '250';
                $this->vdata['returnInfo'] = '请求失败';
                $this->vdata['secure']     = JSON_SECURE;
                $this->vdata['content']= array();
            }else{
                //存在即可进行申请领取佣金
                if($need_info['uid']==$this->userinfo['id']){
                    $this->vdata['returnCode']   = '250';
                    $this->vdata['returnInfo'] = '不可操作';
                    $this->vdata['secure']     = JSON_SECURE;
                    $this->vdata['content']= array();
                }else{
                    //查看认领记录
                    $claim_info = $this->mclaim->get_one(array('uid'=>$this->userinfo['id'],'need_id'=>$need_id));
                    if(empty($claim_info)){
                        $this->vdata['returnCode']   = '250';
                        $this->vdata['returnInfo'] = '不可操作';
                        $this->vdata['secure']     = JSON_SECURE;
                        $this->vdata['content']= array();
                    }else{
                        $this->mneeds->update(array('claim_status'=>4,'updated'=>time()),array('id'=>$need_info['id']));
                        $this->mbalance->update(array('status'=>3,'updated_at'=>time()),array('id'=>$need_info['id']));   //申请中
                        //并且添加一条申领记录
                        $need_apply_data = array(
                            'uid'=>$this->userinfo['id'],
                            'money'=>$claim_info['money'],
                            'claim_id'=>$claim_info['id'],
                            'need_id'=>$need_id,
                            'created'=>time(),
                            'updated'=>time(),
                        );
                        if($this->mneedapply->create($need_apply_data)){
                            /*******添加推送板块**********/
                            $to_uid = $need_info['uid'];
                            $uname = $this->userinfo['uname'];
                            $t_type = 1;
                            $content = $uname.'已申领悬赏佣金，请及时确认并评价';
                            getui_push($to_uid,$t_type,$need_id,$content);
                            $this->vdata['returnCode']   = '200';
                            $this->vdata['returnInfo'] = '成功申请';
                            $this->vdata['secure']     = JSON_SECURE;
                            $this->vdata['content']= array();
                        }else{
                            $this->vdata['returnCode']   = '250';
                            $this->vdata['returnInfo'] = '申请失败';
                            $this->vdata['secure']     = JSON_SECURE;
                            $this->vdata['content']= array();
                        }
                    }
                }
            }
        }
        $this->_send_json($this->vdata);
    }

    /**
     * 评价
     */
    public function envaluate(){
        $claim_id = $this->input->post('claim_id');
        if(!$claim_id){
            $this->vdata['returnCode']   = '250';
            $this->vdata['returnInfo'] = '请求失败';
            $this->vdata['secure']     = JSON_SECURE;
            $this->vdata['content']= array();
        }else{
            $claim_info = $this->mclaim->get_one(array('id'=>$claim_id,'is_assign'=>1));
            if(empty($claim_info)){
                $this->vdata['returnCode']   = '250';
                $this->vdata['returnInfo'] = '无此记录';
                $this->vdata['secure']     = JSON_SECURE;
                $this->vdata['content']= array();
            }else{
                //查询需求的详细信息
                $need_info = $this->mneeds->get_one(array('id'=>$claim_info['need_id']));
                if($need_info['claim_status']==4){
                    if($need_info['uid']==$this->userinfo['id']){
                        $stars = $this->input->post('stars');   //评星
                        //确认评价处理(已完成)
                        $this->mclaim->update(array('stars'=>$stars),array('id'=>$claim_id));
                        $this->mneeds->update(array('claim_status'=>5,'updated'=>time(),'finished'=>time()),array('id'=>$need_info['id']));
                        //更新账户余额处理和评星处理(待完善)
                        //认领方余额增加议价价格,明细记录修改状态为1成功
                        //获取该认领人已获得的评价总星数
                        $user_id = $this->userinfo['id'];
                        $claim_user_id = $claim_info['uid'];
                        $claims = $this->db->query("select count(*) as counts,sum(stars) as total from boc_claim where uid=$claim_user_id and is_assign=1")->result_array();
                        if(!empty($claims)){
                            //$now_stars  评星
                            $total = $claims[0]['total'];
                            $counts = $claims[0]['counts'];
                            $r_stars = round($total/$counts);
                            $correct = $total/$counts;
                            if($correct == $r_stars){
                                $now_stars = $correct;
                            }elseif($correct > $r_stars-0.5){
                                $now_stars = $r_stars;
                            }elseif($correct < $r_stars + 0.5){
                                $now_stars = $r_stars;
                            }elseif($correct == $r_stars-0.5){
                                $now_stars = $correct;
                            }
                        }else{
                            $now_stars = $stars;
                        }


                        //增加认领数和评星数以及余额更新+明细记录  悬赏收入
                        //悬赏收入
                        $money_new = $claim_info['money'];
                        $this->db->query("update boc_account set balance=balance+$money_new,reward=reward+$money_new,stars=$now_stars,claims=claims+1 where id=$claim_user_id");
                        $this->mbalance->update(array('status'=>1,'rid'=>$claim_user_id,'updated_at'=>time()),array('need_id'=>$need_info['id']));   //成功
                        $balance_data_in = array(
                            'uid'=>$claim_user_id,
                            'type'=>5,              //悬赏收入
                            'title'=>$need_info['intro'],
                            'need_id'=>$need_info['id'],
                            'money'=>$money_new,
                            'status'=>1,
                            'pay_ways'=>3,          //余额收入
                            'pay_time'=>time(),
                            'created_at'=>time(),
                            'updated_at'=>time(),
                            'rid'=>$this->userinfo['id'],
                            'payment_sn'=>$need_info['payment_sn'],
                            'pay_code'=>$need_info['order_sn'],
                        );

                        //处理悬赏差价退回
                        //查询补差价订单金额
                        $need_order_info = $this->mneedorder->get_one(array('need_id'=>$need_info['id']));
                        $need_order_money = 0;
                        if(!empty($need_order_info)){
                            $need_order_money = $need_order_info['money'];
                        }
                        $all_money = $need_order_money + $need_info['margin'];
                        if($all_money > $money_new){
                            $surpose_money = $all_money - $money_new;
                            $this->db->query("update boc_account set balance=balance+$surpose_money where id=$user_id");
                            $balance_data_in2 = array(
                                'uid'=>$user_id,
                                'type'=>7,              //悬赏差价退回
                                'title'=>$need_info['intro'],
                                'need_id'=>$need_info['id'],
                                'money'=>$surpose_money,
                                'status'=>1,
                                'pay_ways'=>3,          //余额收入
                                'pay_time'=>time(),
                                'created_at'=>time(),
                                'updated_at'=>time(),
                                'rid'=>0,
                                'payment_sn'=>$need_info['payment_sn'],
                                'pay_code'=>$need_info['order_sn'],
                            );
                            $this->mbalance->create($balance_data_in2);
                        }
                        $this->mbalance->create($balance_data_in);
                        /*******添加推送板块**********/
                        $to_uid = $claim_info['uid'];
                        $uname = $this->userinfo['uname'];
                        $t_type = 1;
                        $content = $uname.'已支付悬赏佣金';
                        getui_push($to_uid,$t_type,$claim_info['need_id'],$content);
                        $this->vdata['returnCode']   = '200';
                        $this->vdata['returnInfo'] = '评价成功';
                        $this->vdata['secure']     = JSON_SECURE;
                        $this->vdata['content']= array();

                    }else{
                        $this->vdata['returnCode']   = '250';
                        $this->vdata['returnInfo'] = '不可操作';
                        $this->vdata['secure']     = JSON_SECURE;
                        $this->vdata['content']= array();
                    }
                }else{
                    $this->vdata['returnCode']   = '250';
                    $this->vdata['returnInfo'] = '不可操作';
                    $this->vdata['secure']     = JSON_SECURE;
                    $this->vdata['content']= array();
                }
            }
        }
        $this->_send_json($this->vdata);
    }

    /**
     * 申请仲裁(发布方和认领方)
     */
    public function arbitrate(){
        $type = $this->input->post('type');
        if(!$type){
            $this->vdata['returnCode']   = '250';
            $this->vdata['returnInfo'] = '请求失败';
            $this->vdata['secure']     = JSON_SECURE;
            $this->vdata['content']= array();
        }else{
            $need_id = $this->input->post('need_id');
            if(!$need_id){
                $this->vdata['returnCode']   = '250';
                $this->vdata['returnInfo'] = '请求失败';
                $this->vdata['secure']     = JSON_SECURE;
                $this->vdata['content']= array();
            }else{
                $need_info = $this->mneeds->get_one(array('id'=>$need_id));
                if(empty($need_info)){
                    $this->vdata['returnCode']   = '250';
                    $this->vdata['returnInfo'] = '悬赏不存在';
                    $this->vdata['secure']     = JSON_SECURE;
                    $this->vdata['content']= array();
                }else{
                    //发布方申请仲裁
                    if($type==1){
                        if($need_info['uid']==$this->userinfo['id']){
                            if($need_info['claim_status']==4){
                                $this->mneeds->update(array('arbitrate'=>1,'updated'=>time()),array('id'=>$need_id));
                                /*******添加推送板块**********/
                                $claim_info = $this->mclaim->get_one(array('is_assign'=>1,'need_id'=>$need_id));
                                $to_uid = $claim_info['uid'];
                                $uname = $this->userinfo['uname'];
                                $t_type = 1;
                                $content = $uname.'已向平台申请仲裁';
                                getui_push($to_uid,$t_type,$need_id,$content);
                                $this->vdata['returnCode']   = '200';
                                $this->vdata['returnInfo'] = '仲裁成功';
                                $this->vdata['secure']     = JSON_SECURE;
                                $this->vdata['content']= array();
                            }else{
                                $this->vdata['returnCode']   = '250';
                                $this->vdata['returnInfo'] = '不可操作';
                                $this->vdata['secure']     = JSON_SECURE;
                                $this->vdata['content']= array();
                            }
                        }else{
                            $this->vdata['returnCode']   = '250';
                            $this->vdata['returnInfo'] = '不可操作';
                            $this->vdata['secure']     = JSON_SECURE;
                            $this->vdata['content']= array();
                        }
                    }elseif($type==2){
                        if($need_info['uid']!=$this->userinfo['id']){
                            if($need_info['claim_status']==4){
                                //查看认领详情
                                $claim_info = $this->mclaim->get_one(array('uid'=>$this->userinfo['id'],'need_id'=>$need_id,'is_assign'=>1));
                                if(empty($claim_info)){
                                    $this->vdata['returnCode']   = '250';
                                    $this->vdata['returnInfo'] = '不可操作';
                                    $this->vdata['secure']     = JSON_SECURE;
                                    $this->vdata['content']= array();
                                }else{
                                    //申请佣金记录时间
                                    $mneedapply = $this->mneedapply->get_one(array('claim_id'=>$claim_info['id']));
                                    if(empty($mneedapply)){
                                        $this->vdata['returnCode']   = '250';
                                        $this->vdata['returnInfo'] = '不可操作';
                                        $this->vdata['secure']     = JSON_SECURE;
                                        $this->vdata['content']= array();
                                    }else{
                                        $create_time = $mneedapply['created'] + 24*3600;
                                        $now_time = time();
                                        if($create_time < $now_time){
                                            $this->mclaim->update(array('arbitrate'=>1,'update_time'=>time()),array('id'=>$claim_info['id']));
                                            $this->mneeds->update(array('c_arbitrate'=>1,'update_time'=>time()),array('id'=>$need_id));
                                            /*******添加推送板块**********/
                                            $to_uid = $need_info['uid'];
                                            $uname = $this->userinfo['uname'];
                                            $t_type = 1;
                                            $content = $uname.'已向平台申请仲裁';
                                            getui_push($to_uid,$t_type,$claim_info['need_id'],$content);
                                            $this->vdata['returnCode']   = '200';
                                            $this->vdata['returnInfo'] = '仲裁成功';
                                            $this->vdata['secure']     = JSON_SECURE;
                                            $this->vdata['content']= array();
                                        }else{
                                            $this->vdata['returnCode']   = '250';
                                            $this->vdata['returnInfo'] = '不可操作';
                                            $this->vdata['secure']     = JSON_SECURE;
                                            $this->vdata['content']= array();
                                        }
                                    }
                                }
                            }else{
                                $this->vdata['returnCode']   = '250';
                                $this->vdata['returnInfo'] = '不可操作';
                                $this->vdata['secure']     = JSON_SECURE;
                                $this->vdata['content']= array();
                            }
                        }else{
                            $this->vdata['returnCode']   = '250';
                            $this->vdata['returnInfo'] = '不可操作';
                            $this->vdata['secure']     = JSON_SECURE;
                            $this->vdata['content']= array();
                        }
                    }
                }
            }
        }
        $this->_send_json($this->vdata);
    }

    /**
     * 撤销处理(发布方)
     */
    public function cancel_needs(){
        $need_id= $this->input->post('need_id');
        if(!$need_id){
            $this->vdata['returnCode']   = '250';
            $this->vdata['returnInfo'] = '请求失败';
            $this->vdata['secure']     = JSON_SECURE;
            $this->vdata['content']= array();
        }else{
            $need_info = $this->mneeds->get_one(array('id'=>$need_id,'status'=>1));
            if(empty($need_info)){
                $this->vdata['returnCode']   = '250';
                $this->vdata['returnInfo'] = '悬赏不存在';
                $this->vdata['secure']     = JSON_SECURE;
                $this->vdata['content']= array();
            }else{
                $uid = $this->userinfo['id'];
                if($need_info['uid']==$uid){
                    if($need_info['claim_status']==1 || $need_info['claim_status']==2){
                        //优先查询是否有权限进行撤销操作
                        $last_cancel = $this->userinfo['last_cancel'];
                        if($last_cancel!=0){
                            if($last_cancel+90*24*3600 < time()){
                                //超过三个月则可发布和撤销的权限
                                //查看当月已经有几条撤销记录
                                $start_time = strtotime(date('Y-m-01'));
                                $end_time = strtotime(date('Y-m-d', strtotime(date('Y-m-01', strtotime(date('Y-m-01'))) . ' +1 month -1 day')))+24*3600-1;
                                //指派中撤销次数  一个月3次机会
                                $claim_res = $this->db->query("select * from boc_needs where cancel_time > $start_time and cancel_time < $end_time and cancel_status=2 and uid=$uid")->result_array();
                                if(count($claim_res) <= 3){
                                    if($need_info['claim_status']==1){
                                        //判断是否无人认领
                                        $claims = $this->mclaim->get_all(array('need_id'=>$need_id));
                                        if(empty($claims)){
                                            $this->mneeds->update(array('cancel_time'=>time(),'cancel_status'=>1,'claim_status'=>7,'updated'=>time()),array('id'=>$need_id));
                                        }else{
                                            $reason = $this->input->post('reason');
                                            if(!$reason){
                                                $this->vdata['returnCode']   = '250';
                                                $this->vdata['returnInfo'] = '请输入撤销原因';
                                                $this->vdata['secure']     = JSON_SECURE;
                                                $this->vdata['content']= array();
                                            }else{
                                                if(count($claim_res)==2){
                                                    //第三次撤销操作，则更新最后一次的撤销时间
                                                    $this->maccount->update(array('last_cancel'=>time()),array('id'=>$this->userinfo['id']));
                                                }
                                                $this->mneeds->update(array('reason'=>trim($reason),'cancel_time'=>time(),'cancel_status'=>2,'claim_status'=>6,'updated'=>time()),array('id'=>$need_id));
                                            }
                                        }
                                        $this->money_return($need_id);
                                    }elseif($need_info['claim_status']==2){
                                        $reason = $this->input->post('reason');
                                        if(!$reason){
                                            $this->vdata['returnCode']   = '250';
                                            $this->vdata['returnInfo'] = '请输入撤销原因';
                                            $this->vdata['secure']     = JSON_SECURE;
                                            $this->vdata['content']= array();
                                        }else{
                                            if(count($claim_res)==2){
                                                //第三次撤销操作，则更新最后一次的撤销时间
                                                $this->maccount->update(array('last_cancel'=>time()),array('id'=>$this->userinfo['id']));
                                            }
                                            $this->mneeds->update(array('reason'=>trim($reason),'cancel_time'=>time(),'cancel_status'=>2,'claim_status'=>6,'updated'=>time()),array('id'=>$need_id));
                                        }
                                        $this->money_return($need_id);
                                    }

                                    $this->vdata['returnCode']   = '200';
                                    $this->vdata['returnInfo'] = '成功撤销';
                                    $this->vdata['secure']     = JSON_SECURE;
                                    $this->vdata['content']= array();
                                }else{
                                    $this->vdata['returnCode']   = '250';
                                    $this->vdata['returnInfo'] = '撤销次数已达三次';
                                    $this->vdata['secure']     = JSON_SECURE;
                                    $this->vdata['content']= array();
                                }
                            }else{
                                $this->vdata['returnCode']   = '250';
                                $this->vdata['returnInfo'] = '撤销权限已被禁用';
                                $this->vdata['secure']     = JSON_SECURE;
                                $this->vdata['content']= array();
                            }
                        }else{
                            //查看当月已经有几条撤销记录
                            $start_time = strtotime(date('Y-m-01'));
                            $end_time = strtotime(date('Y-m-d', strtotime(date('Y-m-01', strtotime(date('Y-m-01'))) . ' +1 month -1 day')))+24*3600-1;
                            $claim_res = $this->db->query("select * from boc_needs where cancel_time > $start_time and cancel_time < $end_time and cancel_status=2 and uid=$uid")->result_array();
                            if(count($claim_res) <= 3){
                                if($need_info['claim_status']==1){
                                    //判断是否无人认领
                                    $claims = $this->mclaim->get_all(array('need_id'=>$need_id));
                                    if(empty($claims)){
                                        $this->mneeds->update(array('cancel_time'=>time(),'cancel_status'=>1,'claim_status'=>7,'updated'=>time()),array('id'=>$need_id));
                                    }else{
                                        $reason = $this->input->post('reason');
                                        if(!$reason){
                                            $this->vdata['returnCode']   = '250';
                                            $this->vdata['returnInfo'] = '请输入撤销原因';
                                            $this->vdata['secure']     = JSON_SECURE;
                                            $this->vdata['content']= array();
                                        }else{
                                            if(count($claim_res)==2){
                                                //第三次撤销操作，则更新最后一次的撤销时间
                                                $this->maccount->update(array('last_cancel'=>time()),array('id'=>$this->userinfo['id']));
                                            }
                                            $this->mneeds->update(array('reason'=>trim($reason),'cancel_time'=>time(),'cancel_status'=>2,'claim_status'=>6,'updated'=>time()),array('id'=>$need_id));
                                        }
                                    }
                                    $this->money_return($need_id);
                                }elseif($need_info['claim_status']==2){
                                    $reason = $this->input->post('reason');
                                    if(!$reason){
                                        $this->vdata['returnCode']   = '250';
                                        $this->vdata['returnInfo'] = '请输入撤销原因';
                                        $this->vdata['secure']     = JSON_SECURE;
                                        $this->vdata['content']= array();
                                    }else{
                                        if(count($claim_res)==2){
                                            //第三次撤销操作，则更新最后一次的撤销时间
                                            $this->maccount->update(array('last_cancel'=>time()),array('id'=>$this->userinfo['id']));
                                        }
                                        $this->mneeds->update(array('reason'=>trim($reason),'cancel_time'=>time(),'cancel_status'=>2,'claim_status'=>6,'updated'=>time()),array('id'=>$need_id));
                                    }
                                    $this->money_return($need_id);
                                }
                                $this->vdata['returnCode']   = '200';
                                $this->vdata['returnInfo'] = '成功撤销';
                                $this->vdata['secure']     = JSON_SECURE;
                                $this->vdata['content']= array();
                            }else{
                                $this->vdata['returnCode']   = '250';
                                $this->vdata['returnInfo'] = '撤销次数已达三次';
                                $this->vdata['secure']     = JSON_SECURE;
                                $this->vdata['content']= array();
                            }
                        }
                    }else{
                        $this->vdata['returnCode']   = '250';
                        $this->vdata['returnInfo'] = '不可操作';
                        $this->vdata['secure']     = JSON_SECURE;
                        $this->vdata['content']= array();
                    }
                }else{
                    $this->vdata['returnCode']   = '250';
                    $this->vdata['returnInfo'] = '不可操作';
                    $this->vdata['secure']     = JSON_SECURE;
                    $this->vdata['content']= array();
                }
            }
        }
        $this->_send_json($this->vdata);

    }

    /**
     * 处理撤销后的押金退回
     */
    public function money_return($need_id=0){
        if(!$need_id){
            return false;
        }else{
            $need_info = $this->mneeds->get_one(array('id'=>$need_id));
            if(empty($need_info)){
                return false;
            }else{
                $this->db->trans_begin();
                $user_id = $need_info['uid'];
                $all_money = $need_info['margin'];
                $this->db->query("update boc_account set balance=balance+$all_money where id=$user_id");
                $this->mbalance->update(array('status'=>5,'updated_at'=>time()),array('id'=>$need_info['id']));   //任务关闭已退回
                if($this->db->trans_status()===false){
                    $this->db->trans_rollback();
                    return false;
                }else{
                    $this->db->trans_commit();
                    return true;
                }
            }
        }
    }

    /**
     * 申请延时
     */
    public function delay_need(){
        $need_id = $this->input->post('need_id');
        if(!$need_id){
            $this->vdata['returnCode']   = '250';
            $this->vdata['returnInfo'] = '不可操作';
            $this->vdata['secure']     = JSON_SECURE;
            $this->vdata['content']= array();
        }else{
            $need_info = $this->mneeds->get_one(array('id'=>$need_id,'is_deleted'=>0));
            if(empty($need_info)){
                $this->vdata['returnCode']   = '250';
                $this->vdata['returnInfo'] = '悬赏不存在';
                $this->vdata['secure']     = JSON_SECURE;
                $this->vdata['content']= array();
            }else{
                if($need_info['is_delay']==1&&$need_info['is_again']==0){
                    $delay = $this->input->post('delay_days');
                    $delay_time = $delay*24*3600 + $need_info['countdown'];
                    $this->mneeds->update(array('countdown'=>$delay_time,'updated'=>time(),'is_again'=>1),array('id'=>$need_id));
                    $this->vdata['returnCode']   = '200';
                    $this->vdata['returnInfo'] = '操作成功';
                    $this->vdata['secure']     = JSON_SECURE;
                    $this->vdata['content']= array();
                }else{
                    $this->vdata['returnCode']   = '250';
                    $this->vdata['returnInfo'] = '不可操作';
                    $this->vdata['secure']     = JSON_SECURE;
                    $this->vdata['content']= array();
                }
            }
        }
        $this->_send_json($this->vdata);
    }

    /**
     * 删除活动或者需求对接
     */
    public function delete_needs(){
        //获取当前用户信息
        $uid = $this->userinfo['id'];
        $need_id = $this->input->post('need_id');
        $need_info = $this->mneeds->get_one(array('id'=>$need_id,'is_deleted'=>0));
        if(empty($need_info)){
            $this->vdata['returnCode']   = '300';
            $this->vdata['returnInfo'] = '记录不存在';
            $this->vdata['secure']     = JSON_SECURE;
            $this->vdata['content']= array();
        }else {
            if($need_info['uid']==$uid){
                if($need_info['type']!=1){
                    $this->db->query("update boc_needs set is_deleted=1 where id=$need_id and uid=$uid");
                    $this->vdata['returnCode']   = '200';
                    $this->vdata['returnInfo'] = '删除成功';
                    $this->vdata['secure']     = JSON_SECURE;
                    $this->vdata['content']= array();
                }else{
                    $this->vdata['returnCode']   = '300';
                    $this->vdata['returnInfo'] = '没有权限';
                    $this->vdata['secure']     = JSON_SECURE;
                    $this->vdata['content']= array();
                }
            }else{
                $this->vdata['returnCode']   = '300';
                $this->vdata['returnInfo'] = '没有权限';
                $this->vdata['secure']     = JSON_SECURE;
                $this->vdata['content']= array();
            }
        }
        $this->_send_json($this->vdata);
    }
}
